<!--历届组长·新增-->

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	    <link rel="stylesheet" href="/static/css/backstage/amazeui.min.css" >
		<link rel="stylesheet" href="/static/css/backstage/admin.css" >
		<link rel="stylesheet" href="/static/css/backstage/app.css" >
		<style>
			.admin-main{
				padding-top: 0px;
			}
			.error{
				color:red;
			}
			.success{
				color:#5eb95e;
			}
		</style>
	</head>
	<body>
		<div class="am-cf admin-main">
		<!-- content start -->
		<div class="admin-content">
			<div class="admin-content-body">
				<div class="am-g">
					<form class="am-form am-form-horizontal"	 method="post"	style="padding-top:10px;" data-am-validator>
						<input type="hidden" value="${groupid}" name="leader[le_groupid]">
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">
								组长ID</label>
							<div class="am-u-sm-9">
								<input style="background:none;" type="text" id="leader" onBlur="checkLeader()" required placeholder="请输入组长ID" data-equal-to="#doc-vld-pwd-1" name="leader[le_memberid]"  required>
								<small id="leaderErr">输入组长ID。</small>
							</div>
						</div>
						<div class="am-form-group">
							<label for="user-name" class="am-u-sm-3 am-form-label">
								任职日期 </label>
							<div class="am-u-sm-9">
								<input type="text"  onBlur="checkTime()" required placeholder="请输入日期" name="leader[le_time]" id="time">
								<small id="timeErr">输入任职日期。</small>
							</div>
						</div>
						<div class="am-form-group">
							<div class="am-u-sm-9 am-u-sm-push-3">
								<input type="button" class="am-btn am-btn-success addGroup" value="添加组长" />
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="/static/js/backstage/jquery-1.8.3.js" ></script>
	<script type="text/javascript" src="/static/js/backstage/plugs.js" ></script>
	<script>
		function checkLeader(){
			var username = document.getElementById('leader');
			var errname = document.getElementById('leaderErr');
			var pattern = /^[1-9]\d{0,}$/;
			if(username.value.length == 0){
				errname.innerHTML="组长id不能为空";
				errname.className="error";
				return false;
			}
			if(!pattern.test(username.value)){
				errname.innerHTML="组长id不符合规范";
				errname.className="error";
				return false;
			}
			else{
				errname.innerHTML="OK";
				errname.className="success";
				return true;
			}
		}

		function checkTime(){
			var username = document.getElementById('time');
			var errname = document.getElementById('timeErr');
			var pattern = /^[1-9]\d{3}-[0-3]\d-[0-3]\d$/;
			if(username.value.length == 0){
				errname.innerHTML="时间不能为空";
				errname.className="error";
				return false;
			}
			if(!pattern.test(username.value)){
				errname.innerHTML="日期格式不正确！格式：“xxxx-xx-xx”";
				errname.className="error";
				return false;
			}
			else{
				errname.innerHTML="OK";
				errname.className="success";
				return true;
			}
		}

		$(".addGroup").click(function() {
			if(checkLeader()&&checkTime())
			{
				$.ajax({
					url:"/backstage/doAddGleader",
					dataType:"json",
					type:"post",
					data:$("form").serialize(),
					success:function(result){
						alert(result.tips);
						window.location.href=location.href;
					},
					error:function(result){
						alert("系统繁忙！");
					 }
				});
			}
		});
	</script>
	</body>
</html>
